package com.pioneer.swing.model;

import com.pioneer.dao.ManifestDAO;
import com.pioneer.dao.DataAccessException;
import com.pioneer.beans.Manifest;
import javax.swing.table.DefaultTableModel;
import java.util.Vector;
import java.util.List;
import java.util.Iterator;

/**
 * Title:        Pioneer Metals Application
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Pioneer Metals
 * @author Gary Chen
 * @version 1.0
 */

public class AllManifestsTable extends DefaultTableModel {

	private ManifestDAO dao;
    public AllManifestsTable(ManifestDAO dao) {
		columnIdentifiers=new Vector();
		columnIdentifiers.add(TableConstants.JOB_NUM);
		columnIdentifiers.add(TableConstants.VESSEL);
		columnIdentifiers.add(TableConstants.ETD);
		columnIdentifiers.add(TableConstants.ETA);
		columnIdentifiers.add(TableConstants.CONTAINER_NOTES);
		this.dao=dao;
		refresh();
    }

	public void refresh()
	{
		try
		{
		    List manifests=dao.getManifests();
			// all rows
			dataVector=new Vector();
			Iterator rows=manifests.iterator();
			//Iterator cols=
			
			while (rows.hasNext())
			{
				Manifest manifest=(Manifest)rows.next();
				Vector row=new Vector();
				row.add(manifest.getJobNum());
				row.add(manifest.getVessel());
				row.add(manifest.getEtd());
				row.add(manifest.getEta());
				row.add(manifest.getContainerNotes());
				dataVector.add(row);
			}
		}
		catch (DataAccessException ex)
		{
			ex.printStackTrace(System.err);
		}
	}

	public boolean isCellEditable(int rowIndex,
                              int columnIndex) {
		return false;
	}

    public static void main(String[] args) {
        //AllManifestsTable allManifestsTable1 = new AllManifestsTable();
    }
}